/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model.BeanUltility;

/**
 *
 * @author chickencake1
 */
public class FilterSpecialCharacters {
    public static String FilterString(String InputString)
    {
        StringBuffer filterBuffer = new StringBuffer();
        if(!hasSpecialCharacter(InputString))
        {
            return InputString;
        }
        
        char c;
        for(int i=0;i<InputString.length();i++)
        {
            c=InputString.charAt(i);
            switch(c)
            {
                case '<' : filterBuffer.append("&lt"); break;
                case '>' : filterBuffer.append("&gt"); break;
                case '"' : filterBuffer.append("&quot"); break;
                case '&' : filterBuffer.append("&amp"); break;
                    default: filterBuffer.append(c); break;
            }
        }
        return filterBuffer.toString();
    }
    private static boolean hasSpecialCharacter(String InputString)
    {
        boolean flag=false;
        if(InputString!=null && InputString.length()>0)
        {
             char c;
            for(int i=0;i<InputString.length();i++)
            {
                c=InputString.charAt(i);
                switch(c)
                {
                    case '<':flag=true; break;
                    case '>':flag=true;break;
                    case '&':flag=true; break;
                    case '"':flag=true; break;
                }           
            }
        }
        return flag;
    }
}
